package com.qf.aop2204.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class NullValidateAspect {
    @Pointcut("@annotation(com.qf.aop2204.aop.NullValidate)")
    public void nullData(){};
    @Before("nullData()")
    public void login(JoinPoint pjp) throws Exception {
        Object[] args = pjp.getArgs();
        System.out.println(args);
        for (int i = 0; i < args.length; i++) {
            if (args[i] == null) {
                log.error("调用方法{}时，第{}个参数为空", pjp.getSignature(), i + 1);
                throw new Exception("参数为空");
            }
        }
    }
}
